<cfmodule template="../../tag/layout.cfm">
<cfscript>
	if( structKeyExists(rc, "ids") && listlen(ids) > 0){
		checkedids = rc.ids;
	}else{
		checkedids = 0;
	}
</cfscript>
<fieldset>
<legend>选择指定用户</legend>
<div id="grid"></div>
</fieldset>
</cfmodule>

<script type="application/javascript">
function getCheckedNames(){
	var rows = $('#grid').datagrid('getSelections');
    var names = [];
    for(var i=0; i<rows.length; i++){
        names.push(rows[i].name);
    }
	return names.toString();
}	

function getCheckedIds(){
	var rows = $('#grid').datagrid('getSelections');
    var ids = [];
    for(var i=0; i<rows.length; i++){
        ids.push(rows[i].id);
    }
    return ids.toString();
}
	
var submitForm = function($dialog,$userids,$usernames) {
	$userids.val( getCheckedIds() );
	var str = '';
	if( getCheckedNames().length > 0 ){
		
		if( getCheckedNames().split(',').length > 3 ){
			str = '你选择了：'	 + getCheckedNames().split(',').slice(0,3) +	'等 ( ' + getCheckedNames().split(',').length	+' ) 个指定用户！';		
		}else{
			str = '你选择了：' + getCheckedNames()+	' ( ' + getCheckedNames().split(',').length	+' ) 个指定用户！';	
		}
				
	}else{
		str = '请选择指定用户！'
	}
	$usernames.val( str );
	$dialog.dialog('destroy');
}	
	
var closeDialog = function($dialog) {
	$dialog.dialog('destroy');
}

$(function(){
	//列表操作
	var gird;
	grid = $('#grid').datagrid({
		fit: false,
		border:false,
		collapsible:false,
		pagination:true,
		singleSelect:false,
		rownumbers:true,
		sortName:'id',
		idField:'id',
		sortOrder:'desc',
		toolbar : '#toolbar',
		url:'?action=user.list',
		columns:[[
			{field:'ck',checkbox:true},
			{field:'id',title:'ID',width:40,sortable:true},
			{field:'name',title:'用户姓名',width:220,sortable:true},
			{field:'sex',title:'性别',width:40,align:'center',sortable:true}
		]],
		onLoadSuccess : function(data) {
			$('.iconImg').attr('src', fw.pixel_0);
			var checkedids = '<cfoutput>#checkedids#</cfoutput>';
			$.each(data.rows, function(index, item){
				if( $.inArray(item.id.toString(),checkedids.split(',')) != -1){
					 grid.datagrid('checkRow', index);
				}
			});
			
		}
	});

});
    
</script>